home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000092_icon-group-sender _Wed Apr 17 16:19:37 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 17 Apr 1996 17:19:38 MST
  2. Date: Wed, 17 Apr 1996 16:19:37 -0500
  3. Message-Id: <199604172119.QAA18647@post.its.mcw.edu>
  4. X-Sender: cdt@post.its.mcw.edu
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset="us-ascii"
  7. To: Hamish Lawson <H.Lawson@tees.ac.uk>
  8. From: cdt@post.its.mcw.edu (Chris D. Tenaglia)
  9. Subject: Re: Splitting and joining strings
  10. Cc: icon-group@cs.arizona.edu
  11. X-Mailer: <PC Eudora Version 1.4>
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13. Status: O
  14.  
  15.  
  16. I have a routine called "parse" I thought was in the IPL. It looks
  17. something like:
  18.  
  19. #
  20. # parse a string into a list with respect to a delimiter
  21. #
  22. procedure parse(line,delims)
  23.   static chars
  24.   chars  := &cset -- delims
  25.   tokens := []
  26.   line ? while tab(upto(chars)) do put(tokens,tab(many(chars)))
  27.   return tokens
  28.   end
  29.  
  30. The delimiter is a cset in this case allowing a little more
  31. tokenizing flexibility. The join thing can be done in one or
  32. two expressions like:
  33.  
  34. text := ""
  35. every text ||:= !items || ":"
  36.  
  37. If you don't mind the trailing delimiter.
  38.  
  39. Chris.
  40.  
  41. >Before I rolled my own I thought I'd have a look in the Icon Program 
  42. Library for a 
  43. >couple of procedures I need.
  44. >
  45. >The first should split a string on a specified separator, along the lines of 
  46. >
  47. >   split("Joe:Sue:Bob:Ann", ":") produces "Joe", "Sue", "Bob", "Ann"
  48. >
  49. >The second should join the elements of a list into a string, with each element 
  50. >separated by a specified separator, along the lines of:
  51. >   join(["Joe", "Sue", "Bob", "Ann"], ":") produces "Joe:Sue:Bob:Ann"
  52. >
  53. >I couldn't find any such procedures in the IPL. Have I missed them?
  54. >
  55. >
  56. >| Hamish Lawson, School of Computing and Mathematics, 
  57. >| University of Teesside, Middlesbrough, Cleveland, UK, TS1 3BA 
  58. >| Tel: +44 1642 212695  Fax: +44 1642 342604
  59. >| E-mail: H.Lawson@tees.ac.uk
  60. >
  61. >
  62.  
  63. Chris Tenaglia (system manager)         |       cdt@post.its.mcw.edu
  64. Medical College of Wisconsin            |
  65. 8701 W. Watertown Plank Rd.             |      Ce que vous voyez est
  66. Milwaukee, WI 53226 (414)456-8765       |      Ce que vous obtenez !
  67.  
  68.